<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <script>
        // index.html
        function jsonp({
            url,
            params,
            callback
        }) {
            return new Promise((resolve, reject) => {
                let script = document.createElement('script')
                window[callback] = function (data) {
                    resolve(data)
                    document.body.removeChild(script)
                }
                params = {
                    ...params,
                    callback
                } // wd=b&callback=show
                let arrs = []
                for (let key in params) {
                    arrs.push(`${key}=${params[key]}`)
                }
                script.src = `${url}?${arrs.join('&')}`
                document.body.appendChild(script)
            })
        }
        jsonp({
            url: 'http://localhost:3000/say',
            params: {
                wd: 'Iloveyou'
            },
            callback: 'show'
        }).then(data => {
            console.log(data)
        })
    </script> -->





















    <script>
        function jsonp({
            url, params, callback
        }) {
            return new Promise((resolve, reject) => {
                let script = document.createElement('script')
                window[callback] = function(data) {
                    resolve(data)
                    document.body.removeChild(script)
                }
                let arr = []
                for (let key in params) {
                    arr.push(`${key}=${params[key]}`)
                }
                arr.push(`callback=${callback}`)
                arrStr = arr.join('&')
                
                script.src = `${url}?${arrStr}`
                document.body.appendChild(script)
            })
        }
        jsonp({
            url: 'http://localhost:5050/say',
            params: {name: 'jiade'},
            callback: 'sayName'
        }).then(res => {

        })
    </script>






</body>

</html>